home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / VSet2.0 / Src / vparse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-20  |  3.2 KB  |  122 lines  |  [TEXT/????]

  1. /*****************************************************************************
  2. *              NCSA HDF Vset release 2.1
  3. *                    May 1991
  4. *
  5. * NCSA HDF Vset release 2.1 source code and documentation are in the public
  6. * domain.  Specifically, we give to the public domain all rights for future
  7. * licensing of the source code, all resale rights, and all publishing rights.
  8. * We ask, but do not require, that the following message be included in all
  9. * derived works:
  10. * Portions developed at the National Center for Supercomputing Applications at
  11. * the University of Illinois at Urbana-Champaign.
  12. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  13. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  14. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  15. *****************************************************************************
  16. * Likkai Ng May 1991 NCSA
  17. *
  18. * vparse.c
  19. * Part of the HDF VSet interface.
  20. *
  21. ************************************************************************/
  22.  
  23. #include <stdio.h>
  24. #include "vg.h"
  25.  
  26. #ifdef SUN
  27. #include <ctype.h> 
  28. #endif
  29.  
  30. #define ISCOMMA(c) ( (c==',')?1:0)
  31.  
  32. /* ------------------------------------------------------------------ */
  33.  
  34. /*
  35. ** Given a string (attrs) , the routine parses it into token strings,
  36. ** and returns a ptr (attrv) to an array of ptrs where the tokens 
  37. ** are stored.  The no of tokens are returned in attrc.
  38. **
  39. ** Currently used only by routines that manipulate field names.
  40. ** As such each field string is truncated to a max length of
  41. ** FIELDNAMELENMAX (as defined in vg.h). For most cases, this
  42. ** truncation doesn't happen because FIELDNAMELENMAX is a big number.
  43. **
  44. ** RETURN -1 if error.
  45. ** RETURN 1 if ok.
  46. **
  47. ** Current implementation: all strings inputs converted to uppercase.    
  48. ** tokens must be separated by COMMAs.
  49. **
  50. ** Tokens are stored in static area sym , and pointers are returned
  51. ** to calling routine. Hence, tokens must be used before next call 
  52. ** to scanattrs.
  53. **
  54. */
  55.  
  56. PRIVATE     char*     symptr[50];
  57. PRIVATE     char         sym[50][FIELDNAMELENMAX+1];
  58. PRIVATE    int         nsym;
  59.  
  60. int scanattrs (attrs,attrc,attrv)       /*@@*/
  61.  
  62. char    *attrs;                /* field string (input) */
  63. int    *attrc;                /* # of fields (output) */
  64. char    ***attrv;            /* array of char ptrs to fields (output) */
  65. {
  66.     char *s, *s0, *ss;
  67.     int i,slen,len;
  68.  
  69.     s = attrs;
  70.     slen = strlen(s);
  71.     nsym = 0;
  72.  
  73.     s0 = s;
  74.     for (i=0;i<slen;i++,s++)
  75.         if ( ISCOMMA(*s) ) {
  76.             len = s-s0; 
  77.             if (len<=0) return(FAIL);
  78.             /* save that token */
  79.             ss = symptr[nsym] = sym[nsym]; 
  80.             nsym++;
  81.  
  82.             if ( len > FIELDNAMELENMAX) len = FIELDNAMELENMAX;
  83.             strncpy(ss, s0, len );
  84.             ss[len] = '\0';
  85.  
  86.             s0 = s+1;
  87.         }
  88.  
  89.     /* save the last token */
  90.     len = s-s0; 
  91.     if (len<=0) return(FAIL);
  92.     ss = symptr[nsym] = sym[nsym]; 
  93.     nsym++;
  94.  
  95.     if ( len > FIELDNAMELENMAX) len = FIELDNAMELENMAX;
  96.     strncpy(ss, s0, len);
  97.     ss[len] = '\0';
  98.  
  99.     /* convert all fields tokens to uppercase */
  100.     for (i=0;i<nsym;i++) {
  101.         s = symptr[i];
  102.         while(*s!='\0') {
  103.             if (*s >='a' && *s <='z') *s=toupper(*s);
  104.             s++;
  105.         }
  106.     }
  107.  
  108.     symptr[nsym] = NULL;
  109.     *attrc = nsym;
  110.     *attrv = (char**) symptr;
  111.  
  112.     return(1); /* ok */
  113.  
  114. } /* scanattrs */
  115.  
  116. /* ------------------------------------------------------------------ */
  117.